<?php

/**
 * page actions.
 *
 * @package    khas
 * @subpackage page
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 3335 2007-01-23 16:19:56Z fabien $
 */
class shopActions extends sfActions
{
    public function preExecute()
    {
        ProjectConfiguration::getApplicationConfiguration('front', 'prod', false)->loadHelpers('Url');        
        
        $this->getUser()->setAttribute('activeSeasonId', 'shop');
    }

    public function executeShow(sfWebRequest $request)
    {
        $product = Doctrine::getTable('Product')->findOneById($request->getParameter('id'));
        $this->forward404Unless($product);
        
        $this->product = $product;
        
        $breadcrumbs = array();
        $breadcrumbs[] = '<span>&raquo;</span><a href="'.url_for('shop/index').'">Бараа</a>';
        $breadcrumbs[] = '<span>&raquo;</span><a href="'.url_for('shop/show?name='.$product).'">'.$product.'</a>';
        $this->getResponse()->setSlot('breadcrumbs', $breadcrumbs);
    }
    
    public function executeCatindex(sfWebRequest $request)
    {
//        $this->getUser()->setAttribute('mainmenu', 'shop');

      	$products = Doctrine::getTable('Product')->findByCatId($request->getParameter('cat_id'));
        $this->forward404Unless($products);
        
        $this->products = $products;
        $this->cat_id = $request->getParameter('cat_id');
        $breadcrumbs = array();
        $breadcrumbs[] = '<span>&raquo;</span><a href="'.url_for('shop/index').'">Дэлгүүр</a>';
        $this->getResponse()->setSlot('breadcrumbs', $breadcrumbs);
    }
    
    public function executeIndex(sfWebRequest $request)
    {
    	$this->getUser()->setAttribute('mainmenu', 'shop');
      	$cats = Doctrine::getTable('ProductCategory')->fetchall();
        $this->forward404Unless($cats);
      	
        $this->cats = $cats;
        $breadcrumbs = array();
        $breadcrumbs[] = '<span>&raquo;</span><a href="'.url_for('shop/').'">Дэлгүүр</a>';
        $this->getResponse()->setSlot('breadcrumbs', $breadcrumbs);
    }
     
}